package decision_tree.pos;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import dao.FileIO;

public class POSManager {
	private static POSManager singleton = new POSManager();
	
	private Map<String, String> map;
	private Set<String> abstractSet;
	private List<String> vocabulary;
	
	private boolean initialized = false;
	
	public static POSManager getInstance() {
		return singleton;
	}
	
	public void initialize(String vocabularyFile, String equivalenceClassFile) {
		map = new HashMap<String, String>();
		List<String> equivalence = FileIO.readFile(equivalenceClassFile);
		for(String line : equivalence) {
			String [] tokens = line.split("\t");
			for(String token : tokens) {
				map.put(token, tokens[0]);
			}
		}
		
		vocabulary = FileIO.readFile(vocabularyFile);
		for(String token : vocabulary) {
			if(!map.containsKey(token)) {
				map.put(token, token);
			}
		}
		
		abstractSet = new HashSet<String>(map.values());
		
		initialized = true;
	}
	
	public String convert(String token) {
		return map.get(token);
	}
	
	public Set<String> getRawSet() {
		return map.keySet();
	}
	
	public Set<String> getAbstractSet() {
		return abstractSet;
	}
	
	public List<String> getVocabulary() {
		return vocabulary;
	}
	
	public boolean isInitialized() {
		return initialized;
	}
}
